package com.cj.bigfileupload;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.util.StringUtils;

/**
 * ClassName: Application <br/>
 * Function: 启动类 <br/>
 * date: 2018/05/08 15:16 <br/>
 *
 * @author chenj
 * @version 1.0.0
 * @since JDK 1.8
 */
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Value("${spring.messages.basename}")
    private String messageBaseName;
    @Value("${spring.messages.cache-seconds:-1}")
    private int messageCacheSeconds;

    /**
     * messageSource configuration
     *
     * @return
     */
    @Bean(name = "messageSource")
    public ResourceBundleMessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        if (StringUtils.hasText(messageBaseName)) {
            messageSource.setBasenames(StringUtils.commaDelimitedListToStringArray(
                    StringUtils.trimAllWhitespace(messageBaseName)));
        }
        messageSource.setCacheSeconds(messageCacheSeconds);
        messageSource.setUseCodeAsDefaultMessage(true);
        messageSource.setDefaultEncoding("utf-8");
        return messageSource;
    }
}
